package br.trainee.web.vo;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="telefone_clinica")
@NamedQueries(value={
		
		@NamedQuery(name="queryBuscarTelefonePorNumeroEDdd", query="select t from TelefoneClinicaVO t where t.telefoneClinica =:telefoneClinica and t.dddClinica =:dddClinica"),
		@NamedQuery(name="queryBuscarTelefonePorId", query="select t from TelefoneClinicaVO t where t.idTelefoneClinica =:idTelefoneClinica")
})
public class TelefoneClinicaVO{
	
	@Id
	@SequenceGenerator(name="sqTelefoneClinica", sequenceName="sq_telefone_clinica", allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sqTelefoneClinica")
	@Column(name="id_telefone_clinica")
	private Long idTelefoneClinica;
	
	@Column(name="telefone_clinica")
	private Long telefoneClinica;
	
	@Column(name="ddd_clinica")
	private Integer dddClinica;
	
	@OneToMany(mappedBy="telefone",fetch=FetchType.LAZY)
	private List<ClinicaTelefoneClinicaVO> listaClinicaTelefone;
	
	@Transient
	private List<ClinicaVO> listaClinicas;
	
	/*
	 * FORMA ERRADA DE RELACIONAMENTO N,N
	 * 
	@ManyToMany(fetch=FetchType.LAZY,mappedBy="telefones")
	private List<ClinicaVO> listaClinicas;
	 */
	 
	/*
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="id_clinica", referencedColumnName="id_clinica")
	private ClinicaVO clinica;
	*/
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="id_tipo_telefone", referencedColumnName="id_tipo_telefone")
	private TipoTelefoneVO tipoTelefone;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="id_status", referencedColumnName="id_status")
	private StatusVO status;
	
	
	public TelefoneClinicaVO() {
		
	}
	
	public Long getIdTelefoneClinica() {
		return idTelefoneClinica;
	}
	public void setIdTelefoneClinica(Long idTelefoneClinica) {
		this.idTelefoneClinica = idTelefoneClinica;
	}
	
	
	public List<ClinicaVO> getListaClinicas() {
		return listaClinicas;
	}
	public void setListaClinicas(List<ClinicaVO> listaClinicas) {
		this.listaClinicas = listaClinicas;
	}

	
	public Long getTelefoneClinica() {
		return telefoneClinica;
	}
	public void setTelefoneClinica(Long telefoneClinica) {
		this.telefoneClinica = telefoneClinica;
	}
	
	
	public Integer getDddClinica() {
		return dddClinica;
	}
	public void setDddClinica(Integer dddClinica) {
		this.dddClinica = dddClinica;
	}
	

	public TipoTelefoneVO getTipoTelefone() {
		return tipoTelefone;
	}
	public void setTipoTelefone(TipoTelefoneVO tipoTelefone) {
		this.tipoTelefone = tipoTelefone;
	}

	
	public List<ClinicaTelefoneClinicaVO> getListaClinicaTelefone() {
		return listaClinicaTelefone;
	}
	public void setListaClinicaTelefone(
			List<ClinicaTelefoneClinicaVO> listaClinicaTelefone) {
		this.listaClinicaTelefone = listaClinicaTelefone;
	}

	public StatusVO getStatus() {
		return status;
	}
	public void setStatus(StatusVO status) {
		this.status = status;
	}
	
	@Override
	public boolean equals(Object objeto) {
		
		if(objeto == null || !(objeto instanceof TelefoneClinicaVO)){
			
			return false;
		}
			
		TelefoneClinicaVO telefone = (TelefoneClinicaVO) objeto;
		
		return telefone.telefoneClinica.equals(this.telefoneClinica) && telefone.dddClinica.equals(this.dddClinica);
	}
	
	@Override
	public int hashCode() {
		
		return this.telefoneClinica.hashCode() + this.dddClinica.hashCode();
	}
	
}
